package com.ynny.librarysystemmanager.task;


import cn.hutool.core.date.LocalDateTimeUtil;
import com.ynny.librarysystemmanager.entity.BookStatus;
import com.ynny.librarysystemmanager.entity.Record;
import com.ynny.librarysystemmanager.mapper.RecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;

@Component
public class RecordTask {

    @Autowired
    RecordMapper recordMapper;
    //希望 在凌晨执行
    @Scheduled(cron = "0 0 0 * * ?")
    public void updateRecordStatus(){

//        System.out.println("updateRecordStatus~~~~");
        //1.查询所有已经逾期的记录
        List<Record> records = recordMapper.selectRecordsLessEndTime();

        //2.修改状态为已逾期
        for (Record record : records) {
            record.setStatus(BookStatus.Overdue.getCode());
            recordMapper.update(record);

        }


    }
}
